package com.yesin.elasticsearch.pojo;

import java.util.Map;

public class SearchRequest {
    private String key;
    private Integer page; // 当前页
    private String sortBy; // 排序关键字
    private Boolean desc; // 排序条件
    private Map<String, Object> filter; // 过滤字段

    private static final Integer DEFUALT_SIZE = 20; // 每页大小，不从页面接收，而是固定大小
    private static final Integer DEFAUALT_PAGE = 1; // 默认页

    public Map<String, Object> getFilter() {
        return filter;
    }

    public void setFilter(Map<String, Object> filter) {
        this.filter = filter;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Integer getPage() {
        if (page == null){
            return DEFAUALT_PAGE;
        }
        // 校验获取页码，不能小于1
        return Math.max(DEFAUALT_PAGE, page);
    }
    public String getSortBy(){
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }

    public Boolean getDesc() {
        return desc;
    }

    public void setDesc(Boolean desc) {
        this.desc = desc;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize(){
        return DEFUALT_SIZE;
    }
}
